<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>数据查询</title>
<link href="styles/general.css" rel="stylesheet" type="text/css" /><link href="styles/main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/sorttable.js"></script>
    <script src="js/utils.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery/uploadify/jquery.min.js"></script>
	<script language="javascript" type="text/javascript" src="js/DatePicker4.72/WdatePicker.js"></script>

<link rel="stylesheet" type="text/css" href="http://ajax.pupkk.com/dojo/1.7.5/dojo/resources/dojo.css" />
	<link rel="stylesheet" type="text/css" href="http://ajax.pupkk.com/dojo/1.7.5/dijit/themes/tundra/tundra.css" />
	<script src="http://ajax.pupkk.com/dojo/1.7.5/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
    <script type="text/javascript">
		dojo.require("dojo.parser");
		dojo.require("dijit.form.DateTextBox");
		dojo.require("dijit.form.FilteringSelect");
		function changecpid()
		{
			var cpidv = dijit.byId("cpid").get('value');
			if(cpidv!="")
			{
				$.get("dataquery_changecp.do?cpid="+cpidv, 
    	           function(data) 
    	           { 
    	            	  document.getElementById("appdiv").innerHTML=data;
    	           });
			}
		}
		function get_query_dimension(dc)
		{
			var dimension = "";
			for (var n = 0; n < dc; n++)
			{
				var id = "dimension[" + n + "]";
				if (document.getElementById(id))
				{
					if(document.getElementById(id).checked)
					{
						if (dimension.length > 0)
							dimension += ";";
						dimension += document.getElementById(id).value;
					}
				}
			}
			return dimension;
		}
		function save()
		{
			var startday = $("#startday").val(),
				endday = $("#endday").val();
			if(startday=="")
			{
				alert("选择要查询的开始日期!");
				return false;
			}
			if(endday=="")
			{
				alert("选择要查询的结束日期!");
				return false;
			}
			var dimension = get_query_dimension(4);
			document.getElementById("dimension").value=dimension;
			$("input[type=submit]").val("正在查询。。。").attr("disabled",true);
			return true;
			
		}
		function changeappversion(){
			$.get("kpay_changeappversion.do?appnumber="+$("#appnumber").val(),function(data){
				$("#appversiondiv").html(data);
			});
		}
	</script>
</head>

<body>
<h1>
        <span class="action-span"></span> <span
            class="action-span1"><a href="mainframe.jsp">
                首页</a> </span><span id="search_id" class="action-span1">- Kpay数据分析查询</span>
    </h1>
    <form name="form1" id="form1" method="post" action="kpay_allQuery.do?type=query" onsubmit="return save();">
    <input type="hidden" id="dimension" name="dimension" />
    <div class="form-div"   style="margin-bottom: 5px;width: 100%;" align="center">
        <table width="90%"  cellspacing="1" cellpadding="2" > 
            <tbody>
				<tr height="30">
					<td>开始日期：</td>
					<td align="left"><input type="text" size="25" name="startday" id="startday" 
					    onFocus="WdatePicker({isShowWeek:true,dateFmt:'yyyyMMdd',skin:'whyGreen'})" 
					     value="<s:property value="startday" />"/></td>
					<td>结束日期：</td>
					<td align="left"><input type="text" size="25" name="endday" id="endday" 
					    onFocus="WdatePicker({isShowWeek:true,dateFmt:'yyyyMMdd',skin:'whyGreen'})" 
					     value="<s:property value="endday" />"/></td>
					<td>运营商：</td>
					<td>
						<select id="alldata.operator" name="alldata.operator" style="width:175px" >
							<option value="">--请选择--</option>
							<option <s:if test="'中国移动'.equals(alldata.operator)">selected</s:if> value="中国移动">中国移动</option>
							<option <s:if test="'中国联通'.equals(alldata.operator)">selected</s:if> value="中国联通">中国联通</option>
							<option <s:if test="'中国电信'.equals(alldata.operator)">selected</s:if> value="中国电信">中国电信</option>
						</select>
					</td>
					<td rowspan="2"> 
					  <input id="dimension[0]" type="checkbox" value="day" checked ><label for="dimension[0]">日&nbsp;&nbsp;&nbsp;&nbsp;期</label>
					  &nbsp;<input id="dimension[3]" type="checkbox" value="operator" <s:if test="dimension.indexOf('operator')>-1">checked</s:if>><label for="dimension[3]">运营商</label>
					  <br />
					  <br />
					  <input id="dimension[1]" type="checkbox" value="channel" <s:if test="dimension.indexOf('channel')>-1">checked</s:if>><label for="dimension[1]">渠&nbsp;&nbsp;&nbsp;&nbsp;道</label>
					  &nbsp;<input id="dimension[2]" type="checkbox" value="app" <s:if test="dimension.indexOf('app')>-1">checked</s:if>><label for="dimension[2]">游&nbsp;&nbsp;&nbsp;&nbsp;戏</label>
					</td>
				</tr>
				<tr height="30">
					<td>游戏：</td>
					<td align="left">
					<select id="appnumber" name="appnumber" onchange="changeappversion();" style="width:175px">
						<option value="">--请选择--</option>
						<s:iterator value="applist">
						<option value='<s:property value="appnumber" />'><s:property value="appname" /></option>
						</s:iterator>
					</select>
					</td>
					<td>版本：</td>
					<td><div id="appversiondiv"><jsp:include page="_changeappversion.jsp" /></div></td>
					<td>渠道：</td>
					<td>
					<select id="alldata.channelid" name="alldata.channelid" style="width:175px">
						<option value="-1">--请选择--</option>
						<s:iterator value="channellist1">
						<option value='<s:property value="id" />'><s:property value="name" /></option>
						</s:iterator>
					</select>
					</td>
					
				</tr>
				<tr>
					<td align="center" colspan="7"><input type="submit" value=" 查询 " class="button" /></td>
				</tr>
			</tbody>
		</table>
	</div>
   <!-- start ad menu list -->
   <div class="list-div" id="listDiv" style="margin-bottom: 5px;width: 100%;"  align="center">
    <s:if test="type.equals('query')">
    <table width="90%" class="sortable" id="sortable" cellspacing="1" cellpadding="2" align="center">
         <tbody>
         <tr>
         	<s:if test="%{checkQueryDimension(dimension,'day')}">
             <th height="20">日期</th>
            </s:if>
            <s:if test="%{checkQueryDimension(dimension,'operator')}">
             <th height="20">运营商</th>
            </s:if>
            <s:if test="%{checkQueryDimension(dimension,'channel')}">
             <th height="20">渠道</th>
            </s:if>
            <s:if test="%{checkQueryDimension(dimension,'app')}">
             <th height="20">游戏</th>
            </s:if>
            <th>收入/自有</th>
         	<th>新增用户/自有</th>
         	<th>活跃用户/自有</th>
         	<th>付费用户/自有</th>
         	<th>付费次数/自有</th>
         	<th>ARPU/自有</th>
         </tr>
         <s:if test="alldatalist.size()>0">
         <s:set name="t_fee" value="0"></s:set>
         <s:set name="t_feekpay" value="0"></s:set>
         <s:set name="t_newuser" value="0"></s:set>
         <s:set name="t_newuserkpay" value="0"></s:set>
         <s:set name="t_activeuser" value="0"></s:set>
         <s:set name="t_activeuserkpay" value="0"></s:set>
         <s:set name="t_payuser" value="0"></s:set>
         <s:set name="t_payuserkpay" value="0"></s:set>
         <s:set name="t_paynum" value="0"></s:set>
         <s:set name="t_paynumkpay" value="0"></s:set>
		 <s:iterator value="alldatalist" status="i">
			<tr>
				<s:if test="%{checkQueryDimension(dimension,'day')}">
				<td style="background-color: rgb(255, 255, 255);"><s:property value="day" /></td>
				</s:if>
				<s:if test="%{checkQueryDimension(dimension,'operator')}">
				<td style="background-color: rgb(255, 255, 255);">
					<s:if test="operator.length()==0">未知</s:if>
					<s:else><s:property value="operator" /></s:else></td>
				</s:if>
				<s:if test="%{checkQueryDimension(dimension,'channel')}">
				<td style="background-color: rgb(255, 255, 255);">
				<s:if test="channelid!=-1"><s:property value="channellist[channelid].name" /></s:if>
				<s:else>未知</s:else></td>
				</s:if>
				<s:if test="%{checkQueryDimension(dimension,'app')}">
				<td style="background-color: rgb(255, 255, 255);"><s:set var="appname" value="appversion[appversionnumber].appname" />
				<s:if test="#appname==null||#appname.length()==0">未知</s:if>
				<s:else><s:property value="#appname" /></s:else></td>
				</s:if>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="%{formatfee(fee)}" />/<s:property value="%{formatfee(feekpay)}" /></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="newuser" />/<s:property value="newuserkpay" /></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="activeuser" />/<s:property value="activeuserkpay" /></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="payuser" />/<s:property value="payuserkpay" /></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="paynum" />/<s:property value="paynumkpay" /></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="%{computearpu1(fee,activeuser)}"/>/<s:property value="%{computearpu1(feekpay,activeuserkpay)}"/></td>
			</tr>
			 <s:set name="t_fee" value="#t_fee+fee"></s:set>
			 <s:set name="t_feekpay" value="#t_feekpay+feekpay"></s:set>
			 <s:set name="t_newuser" value="#t_newuser+newuser"></s:set>
	         <s:set name="t_newuserkpay" value="#t_newuserkpay+newuserkpay"></s:set>
	         <s:set name="t_activeuser" value="#t_activeuser+activeuser"></s:set>
	         <s:set name="t_activeuserkpay" value="#t_activeuserkpay+activeuserkpay"></s:set>
	         <s:set name="t_payuser" value="#t_payuser+payuser"></s:set>
	         <s:set name="t_payuserkpay" value="#t_payuserkpay+payuserkpay"></s:set>
	         <s:set name="t_paynum" value="#t_paynum+paynum"></s:set>
	         <s:set name="t_paynumkpay" value="#t_paynumkpay+paynumkpay"></s:set>
			</s:iterator>
			<tr>
				<td style="background-color: rgb(255, 255, 255);" colspan="<s:property value="%{getQueryDimensionCount(dimension)}"/>">总计</td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="%{formatfee(#t_fee)}"/>/<s:property value="%{formatfee(#t_feekpay)}"/></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="#t_newuser"/>/<s:property value="#t_newuserkpay"/></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="#t_activeuser"/>/<s:property value="#t_activeuserkpay"/></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="#t_payuser"/>/<s:property value="#t_payuserkpay"/></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="#t_paynum"/>/<s:property value="#t_paynumkpay"/></td>
				<td style="background-color: rgb(255, 255, 255);"><s:property value="%{computearpu1(#t_fee,#t_activeuser)}"/>/<s:property value="%{computearpu1(#t_feekpay,#t_activeuserkpay)}"/></td>
			</tr>
			</s:if>
			<s:else>
			<tr>
				<td colspan="<s:property value="%{getQueryDimensionCount(dimension)+6}"/>" align="center">无</td>
			</tr>
			</s:else>
	  </tbody>
	</table>
	</s:if>
  </div>
  </form>
 <!--Bottom开始-->
    <script language="JavaScript">

if (document.getElementById("listDiv"))
{
  document.getElementById("listDiv").onmouseover = function(e)
  {
    obj = Utils.srcElement(e);

    if (obj)
    {
      if (obj.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode;
      else if (obj.parentNode.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode.parentNode;
      else return;

      for (i = 0; i < row.cells.length; i++)
      {
        if (row.cells[i].tagName != "TH") row.cells[i].style.backgroundColor = '#eeeded';
      }
    }

  }

  document.getElementById("listDiv").onmouseout = function(e)
  {
    obj = Utils.srcElement(e);

    if (obj)
    {
      if (obj.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode;
      else if (obj.parentNode.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode.parentNode;
      else return;

      for (i = 0; i < row.cells.length; i++)
      {
          if (row.cells[i].tagName != "TH") row.cells[i].style.backgroundColor = '#FFF';
      }
    }
  }

}

    </script>
    
<div id="footer">
<br />
<s:property value="bottom"/></div>
    <!--Bottom结束-->
</body>
</html>